package org.blogspot.t0yv0.marcalog.view

import java.io._
import java.util.Properties
import org.apache.velocity._
import org.apache.velocity.app._

trait TemplateEngine {
  val variables = collection.mutable.Map.empty[String,Object]

  variables.put("enc", Encoder)

  private val engine = {
    val p = new Properties();
    p.setProperty("runtime.log.logsystem.class",
                  "org.apache.velocity.runtime.log.NullLogSystem");
    val e = new VelocityEngine(p);
    e.init();
    e
  }

  def template(tpl: String, out: Writer) {
    var ctx = new VelocityContext();
    for ((x, y) <- variables) {
      ctx.put(x, y);
    }
    engine.mergeTemplate(tpl + ".vm", "utf-8", ctx, out);
  }

}

